<? $page_title='生成采购订单' ?>
<?include "FASHION/page_header.phtml"?>

<form action="<? url('indent-save') ?>" method="post" id="form1">
<table class="list"><tbody>
		
<tr class="nobg">
	<td colspan="12"><div class="right"><? $summary.demands ?></div></td>
</tr>
<tr class="nobg">
	<th><input type="checkbox" onclick="$('#form1 input:checkbox:enabled').attr('checked', this.checked);" /></th>
	<th>状态</th>
	<th>供应商</th>
	<th>材料编号</th>
	<th>材料名称</th>
	<th>品牌</th>
	<th>规格</th>
	<th>单位</th>
	<th>数量</th>
	<th>单价</th>
	<th>金额</th>
	<th>备注</th>
</tr>

<{foreach item=s from=$items}>

	<{if $s.state < DemandItems::STATE_QUOTE}>
		<tr class="disabled">
			<td><input type="checkbox" disabled /></td>
			<td class="state"><?=  SummaryHelper::state2txt($s.state) ?></td>
			<td></td>
	<{elseif $s.state==DemandItems::STATE_QUOTE}>
		<tr>
			<td><input type="checkbox" name="ware_id[]" value="<{$s.ware_id}>" supplier_id="<? $s.supplier_id ?>" /></td>
			<td class="state"><?=  SummaryHelper::state2txt($s.state) ?></td>
			<td><{$s.supplier_name}></td>
	<{elseif $s.state == DemandItems::STATE_INDENT}>
		<{if $ismodify && $stuffs[$s.ware_id] }>
			<tr><td><input type="checkbox" name="ware_id[]" value="<{$s.ware_id}>" supplier_id="<? $s.supplier_id ?>" checked /></td>
		<{else}>
			<tr class="disabled"><td></td>
		<{/if}>
			<td class="state"><?=  SummaryHelper::state2txt($s.state) ?></td>
			<td><{$s.supplier_name}></td>
	<{elseif $s.state == DemandItems::STATE_FAIL}>
		<tr class="disabled">
			<td></td>
			<td class="state"><?=  SummaryHelper::state2txt($s.state) ?></td>
			<td></td>
	<{/if}>

		<td class="nobr"><{$s.sno}></td>
		<td><{$s.name}></td>
		<td><{$s.brand}></td>
		<td><{$s.specific}></td>
		<td class="center"><{$s.unit}></td>
		<td><div class="decimal"><{$s.amount}></div></td>
		<td><div class="decimal fnum"><{$s.price}></div></td>
		<td><div class="decimal fnum"><{= $s.amount * $s.price}></div></td>

	<{if $s.state < DemandItems::STATE_QUOTE}>
		<td><input type="text" disabled size="8" /></td>
	<{elseif $s.state==DemandItems::STATE_QUOTE}>
		<td><input type="text" name="wremark[<? $s.ware_id ?>]" size="8" /></td>
	<{elseif $s.state == DemandItems::STATE_INDENT}>
		<td>&nbsp;</td>
	<{elseif $s.state == DemandItems::STATE_FAIL}>
		<td>无法采购</td>
	<{/if}>

</tr>
<{/foreach}>
</tbody></table>

<table class="select">
<tr>
	<td>PR NO. ： &nbsp; </td>
	<td align="left"><input type="text" name="pr_no" value="<?php
			echo $indent ? $indent['pr_no'] : $summary['demands'];
		?>" /></td>
</tr>
<tr>
	<td class="nowrap">特殊说明： &nbsp; </td>
	<td style="text-align:left">
		<textarea style="width:90%;" rows="3" name="remark"><? $indent.remark ?></textarea>
	</td>
</tr>
</table>

<br/>
<div class="center">
	<INPUT TYPE="button" class="button" value="返回" onclick="history.back(-1)"> &nbsp;
	<INPUT TYPE="submit" class="button" value="生成采购单" />
</div>

<{if $ismodify}>
	<input type="hidden" name="indent_id" value="<{$indent.id}>" />
	<input type="hidden" name="sno" value="<{$indent.sno}>" />
	<input type="hidden" name="id" value="<{$indent.summary_id}>" />
<{else}>
	<input type="hidden" name="id" value="<?=fetch_a_int('id')?>" />
<{/if}>
	<input type="hidden" name="supplier_id" value="" />
</form>

<script>
ajax_form({
	before:function(){
		var a = [];
		$('#form1 input[supplier_id]:checkbox:checked').each(function(){
			a.push($(this).attr('supplier_id'));
		});
		a = $.unique(a);
		if(a.length >1){
			show_alert("供应商冲突");
			return false;
		}
		else if(a.length==0){
			show_alert("请选择至少一个材料生成订单");
			return false;
		}
		//$('input[name=supplier_id]').val(a[0]);
		return confirm("确认要按选中材料生成采购订单吗？");
	}
});
</script>

<?include "FASHION/page_footer.phtml"?>